const app = new Vue({
  el: "#app",
  // 在此处补全代码，实现二级菜单搜索功能
  data: {
    list: [],
    inputText: "",
  },
  async created() {
    const { data } = await axios.get("./data.json");
    this.list = data;
  },
  methods: {
    testList(item) {
      if (JSON.stringify(item.children))
        return JSON.stringify(item.children).includes(this.inputText);
    },
  },
  computed: {
    filterList() {
      if (this.inputText.trim() === "") return this.list;
      else {
        return this.list.filter(
          (item) =>
            item.meta.title.includes(this.inputText) || this.testList(item)
        );
      }
    },
  },
});
